//定时任务服务
import axios from 'axios';
import {cosSystem} from '@/stores/system.js';
const service = axios.create({
  baseURL: '/', // 接口请求地址
  timeout: 1500000, // 请求超时时间
  headers: {
    'Content-Type': 'application/json ; charset=UTF-8',
  },
  withCredentials: true,
});

service.defaults.transformRequest = data => JSON.stringify(data);
service.interceptors.request.use(
  Config => {
    const store = cosSystem();
    let token = store.powerJob.jwtToken||null;
    if (token != null) {
      token = token.replace(/\"/g, '');
    }
    token & (Config.headers.PowerJwt = token);
    return Config;
  },
  error => {
    return Promise.reject(error);
  }
);

service.interceptors.response.use(response => {
  if (response.status == 'OK' || 200) {
    const { success, data, message } = response.data;
    if(success&&data){
        const {data,index,pageSize,totalItems,totalPages} = response.data.data;
       if(pageSize){  
        let rs = {
          content: data,
          page: {number: index,
              size: pageSize,
              totalElements: totalItems,
              totalPages: totalPages
            }
         }
         return rs;
       }else{
        return response.data;
       }
    }else{
      return response.data;
    }
  } else if (code == 'error' || 'exception') {
    Modal.message({ message: msg, status: 'info' });
  } else if (code == 'warning') {
    Modal.message({ message: msg, status: 'warning' });
  } else {
    Modal.message({ message: '请求失败！！！', status: 'error' });
  }
});

export default service;
